package 竞赛.NO_399;

/**
 * 创建时间： 2024-05-26 10:35
 **/
public class 压缩字符串III_100326 {
    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.compressedString("aaaaaaaaaaaaaabb"));
    }

    static class Solution {
        public String compressedString(String word) {
            StringBuilder ans = new StringBuilder();

            while (word.length() > 0) {
                char pre = word.charAt(0);
                int index = 1;
                while (word.length() > index && index < 9 && word.charAt(index) == pre) {
                    index++;
                }
                ans.append(index);
                ans.append(pre);
                word = word.substring(index);
            }
            return ans.toString();
        }
    }
}

